package com.lxy.sentinel.controller;

import com.lxy.sentinel.service.TestSentinelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

/**
 * @author lixinyang
 * @className: TestSentinelController
 * @description: TODO
 * @date 2022/04/28日  13:08
 */

@RestController
public class TestSentinelController {

    @Autowired
    private TestSentinelService service;

    /**
     * @param name
     * @description: NULL
     * @return: java.lang.String
     * @author: lixinyang
     * @date: 2022/4/28 13:09
     */
    @GetMapping(value = "/hello/{name}")
    public String apiHell(@PathVariable("name") String name){
        return service.sayHello(name);
    }

    @GetMapping("/sentinel1")
    public String sentinel1(){
        //模拟一次网络延时
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "sentinel1";
    }
    @GetMapping("/sentinel2")
    public String sentinel2() throws InterruptedException {
//        throw new Exception("错误");
        System.out.println(1/0);
//        TimeUnit.SECONDS.sleep(3);
        return "测试高并发下的问题";
    }

}
